package life;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

class Empyloee{
    private String name;
    private String id="";
    private int year;
    private int baseSalary=3000;
    public static int num=0;

    public Empyloee() {
        num++;
        this.id=this.id+num;
    }
    public Empyloee(String name, int year) {
        this();
        this.name = name;
        this.year = year;
    }
    public double salary(){
        return this.baseSalary+this.baseSalary*this.year*0.1;
    }
    @Override
    public String toString(){
        return "工号:"+this.id+" 姓名:"+this.name+" 工资:"+this.salary();
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public int getYear() {
        return year;
    }
    public void setYear(int year) {
        this.year = year;
    }

}
class Manager extends Empyloee{
    public Manager(String name,int year){
        super(name,year);
    }
    @Override
    public double salary(){
        return super.salary()+1000;
    }

}
class Department {
    private String name;
    private String mgr;
    private List<Empyloee> empyloees = new ArrayList<>();
    public Department(String name){
        this.name=name;
    }

    public List<Empyloee> getEmpyloees() {
        return empyloees;
    }

    public void setEmpyloees(List<Empyloee> empyloees) {
        this.empyloees = empyloees;
    }

    public void add(Empyloee e){
        empyloees.add(e);
    }
    public double avagerSalary(){
        double average;
        double sum=0.0;
        List<Empyloee> empyloeeList = this.empyloees;
        for (Empyloee e :empyloeeList){
            sum+=e.salary();
        }

        average=sum/(empyloeeList.size());
        return average;
    }



    public void print(Manager m){
        System.out.println("编号:"+m.getId()+" 部门经理:"+m.getName()+" 工龄:"+m.getYear()+" 工资:"+m.salary());
        System.out.println("部门平均工资:"+avagerSalary());
//        //迭代器遍历
//        Iterator<Empyloee> it = list.iterator();
//        while(it.hasNext()){
//            Empyloee e = it.next();
//            //System.out.println(e.getId());
//            System.out.println(e.toString());
//        }
        this.getEmpyloees().stream().map(Empyloee::toString
        ).forEach(System.out::println);

        System.out.println("=======================");
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getMgr() {
        return mgr;
    }
    public void setMgr(String mgr) {
        this.mgr = mgr;
    }

}
public class WMS {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Department d1 = new Department("软件开发部");
        Manager mgr1 = new Manager("赵丽丽",3);

        Empyloee e1 = new Empyloee("李小成",2);
        Empyloee e2 = new Empyloee("王小成",1);
        Empyloee e3 = new Empyloee("路小成",5);
        Empyloee e4 = new Empyloee("孙小成",4);
        d1.getEmpyloees().add(e1);
        d1.getEmpyloees().add(e2);
        d1.getEmpyloees().add(e3);
        d1.getEmpyloees().add(e4);
        d1.getEmpyloees().add(mgr1);
        d1.print(mgr1);
        Department d2 = new Department("数据分析部");
        Manager mgr2 = new Manager("李丽丽",5);

        Empyloee e5 = new Empyloee("李小然",2);
        Empyloee e6 = new Empyloee("王小然",3);
        Empyloee e7 = new Empyloee("路小然",2);
        Empyloee e8 = new Empyloee("孙小然",4);
        d2.getEmpyloees().add(e5);
        d2.getEmpyloees().add(e6);
        d2.getEmpyloees().add(e7);
        d2.getEmpyloees().add(e8);
        d2.getEmpyloees().add(mgr2);
        d2.print(mgr2);
    }

}
